//
//  DMMyOrderCell.m
//  DistributionMall
//
//  Created by JHnoplan on 2018/10/16.
//  Copyright © 2018年 JHnoplan. All rights reserved.
//

#import "DMMyOrderCell.h"

@implementation DMMyOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code

    
    [self setUI];
}

-(void)setUI{
    
    _firstBt.layer.borderWidth = 1;
    _secondBt.layer.borderWidth = 1;
    _thirdBt.layer.borderWidth = 1;
    _firstBt.layer.borderColor = RGBCOLOR(121, 121, 121).CGColor;
    _secondBt.layer.borderColor = RGBCOLOR(121, 121, 121).CGColor;
    _thirdBt.layer.borderColor = DMMainColor.CGColor;

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)buttonClick:(UIButton *)sender {
    if (_clickButton) {
        _clickButton(sender.titleLabel.text);
    }
}

-(void)setModel:(KDisOrderModel *)model{
    _model = model;
    //待付款
    if ([model.soStatus isEqualToString:@"awaiting_pay"]) {
        self.thirdBt.hidden = NO;

        [self.thirdBt setTitle:@"去支付" forState:UIControlStateNormal];
        [self.secondBt setTitle:@"取消订单" forState:UIControlStateNormal];
        self.thirdBt.hidden = NO;
        self.secondBt.hidden = NO;
        self.firstBt.hidden = YES;
        self.statusLb.text = @"待付款";
        
        //待发货
    }else if ([model.soStatus isEqualToString:@"awaiting_ship"]) {
        self.thirdBt.hidden = YES;
        self.secondBt.hidden = YES;
        self.firstBt.hidden = YES;
        self.statusLb.text = @"待发货";
        
        //待收货
    }else if ([model.soStatus isEqualToString:@"shipped"]){
        
        [self.thirdBt setTitle:@"确认收货" forState:UIControlStateNormal];
        [self.secondBt setTitle:@"查看物流" forState:UIControlStateNormal];
        self.thirdBt.hidden = NO;
        self.secondBt.hidden = NO;
        self.firstBt.hidden = YES;
        self.statusLb.text = @"待收货";
        
        //待评价
    }else if ([model.soStatus isEqualToString:@"completed"]){
        [self.thirdBt setTitle:@"去评价" forState:UIControlStateNormal];
        [self.secondBt setTitle:@"查看物流" forState:UIControlStateNormal];
        [self.firstBt setTitle:@"删除订单" forState:UIControlStateNormal];
        self.thirdBt.hidden = NO;
        self.secondBt.hidden = NO;
        self.firstBt.hidden = NO;
        self.statusLb.text = @"已收货";
        if (model.soItemViews.count>0) {
            
            KDisOrderItemModel * orderItemModel = model.soItemViews[0];
            if ([orderItemModel.isReview isEqualToString:@"N"]) {
                self.thirdBt.hidden = NO;
                
            }else{
                self.thirdBt.hidden = YES;
            }
        }

    }
    self.numLb.text =[NSString stringWithFormat:@"共%@件商品 合计：¥%@",model.prodQty,model.total];
    
    if (model.soItemViews.count>0) {
        KDisOrderItemModel * itemModel = model.soItemViews[0];
        self.titleLb.text = itemModel.name;
        
        [self.headImage sd_setImageWithURL:[NSURL URLWithString:itemModel.mainCloudPath] placeholderImage:[UIImage imageNamed:@"moren_touxiang"]];
    }
}

@end
